$(function() {
	$('.succeedCase_right div img').eq(0).addClass('pitch')
	homeBanner()	//banner图
	introduction() //企业简介
	recommendProject(0) //成功案例
	allNews()  //新闻中心
	partnerCompany()  //合作伙伴
})
//banner图
function homeBanner() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/homeBanner/',
		dataType: 'json',
		success: function(res) {
			// console.log(res.banner_list)
			var list = res.banner_list
			for (var i = 0; i < list.length; i++){
				var divs = $('<div class="item">'+
					'<img class="hidden-xs" src="'+urlBox+list[i].banner_img+'" alt="...">'+
					'<img class="visible-xs-block" src="'+urlBox+list[i].banner_img_mobile+'" alt="">'+
				'</div>')
				var li = $('<li data-target="#carousel-example-generic" data-slide-to="1"></li>')
				$(".bannerBox .carousel-inner").append(divs);
				$(".bannerBox .carousel-indicators").append(li);
				
			}
			$('.bannerBox .carousel-inner>div').eq(0).addClass('active')
			$('.bannerBox .carousel-indicators>li').eq(0).addClass('active')
		}
			
	})
}

//企业简介
function introduction() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/introduction/',
		dataType: 'json',
		success: function(res) {
			var list = res.introduction_info
			// console.log(list)
			$('.understand_right .hidden-xs').text('以德兴业，康泰万家')
			$('.understand_right p').html(list.movement_intro)
			$('.understand_left img').attr('src',list.banner_img)
			
			$('.regard p').html(list.movement_intro)
		}
			
	})
}

//成功案例
function recommendProject(id) {
	$('.succeedCase .title').text('')
	$('.succeedCase p').html('')
	$('.succeedCase .enterButton').empty()
	$('.succeedCase_right>img').attr('src','')
	$(".succeedCase_right.visible-xs-block div").empty();
	$(".succeedCase_right.hidden-xs div").empty();
	
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/recommendProject/',
		dataType: 'json',
		success: function(res) {
			var list = res.category_list
			// console.log(list)
			if (list.length != 0) {
				$('.succeedCase .title').text(list[id].project_name)
				$('.succeedCase p').html(list[id].intro)
				$('.succeedCase .enterButton').append('<a href="case_particulars.html?project_id='+list[id].project_id+'">查看详情</a>')
				$('.succeedCase_right>img').attr('src',urlBox+list[id].banner_url)
				// $('.succeedCase_right>img').attr('src','img/pc/index/shouye_tu01.png')
				for (var i = 0; i < list.length; i++) {
					var img = $('<img src="'+ urlBox + list[i].banner_url +'" onclick="successful(this,'+i+')">')
					var imgs = $('<a href="case_particulars.html?project_id='+list[i].project_id+'"><img src="'+urlBox+ list[i].banner_url +'" ></a>')
					$(".succeedCase_right.hidden-xs div").append(img);
					$(".succeedCase_right.visible-xs-block div").append(imgs);
				}
				
				$('.succeedCase_right div img').eq(id).addClass('pitch')
				$('.succeedCase').removeClass('PC_height')
			} 
			
			
		}
			
	})
}

//成功案例
function successful(that,id){
	$('.succeedCase').addClass('PC_height')
	recommendProject(id)
	// console.log($(that)[0].src)
	$('.succeedCase_right div img').removeClass('pitch')
	$(that).addClass('pitch')
}


//新闻中心
function allNews() {
	$.ajax({
		type: 'POST',
		url: urlBox+'/api/allNews/',
		data:{
			page: 1,
			size: 5
		},
		dataType: 'json',
		success: function(res) {
			// console.log(res.news_list)
			var list = res.news_list.reverse()
			if (list.length != 0) {
				for (var i = 0; i < list.length; i++) {
					if(i < 3){
						var divs = $(
						'<div class="journalism_body">'
							+'<div class="hidden-xs">'
								+'<div class="title">'
									+'<div>'+list[i].title+'</div>'
									+'<div class="hidden-xs">'+list[i].create_time+'</div>'
								+'</div>'
								+'<p>'+list[i].movement_intro+'</p>'
								+'<div class="enterButton">'
									+'<a href="journalism_particulars.html?id='+list[i].id+'">查看详情</a>'
								+'</div>'
								
							+'</div>'
							+'<a href="journalism_particulars.html?id='+list[i].id+'" class="visible-xs-block">'
								+'<div>'
									+'<div class="title">'+list[i].title+'</div>'
									+'<p>'+list[i].movement_intro+'</p>'
								+'</div>'
								+'<img src="'+urlBox + list[i].img_url+'">'
							+'</a>'
						+'</div>'
						)
						$(".journalism_right").append(divs);
					}
					let div = `<a href="journalism_particulars.html?id=${list[i].id}">
									<span>${list[i].create_time}</span>
									|
									<div>${list[i].title}</div>
								</div></a>`
					$(".titleBox .journalismList").prepend(div);
				}
			}
		}
			
	})
}

//合作伙伴	
function partnerCompany() {
	$.ajax({
		type: 'GET',
		url: urlBox+'/api/partnerCompany/',
		dataType: 'json',
		success: function(res) {
			var list = res.company_list
			// console.log(list.length)
			if (list.length != 0) {
				for (var i = 0; i < list.length; i++) {
					var img = $('<img src="'+ urlBox + list[i].img_url +'" title="'+ list[i].partner_name +'">')
					$(".bankBox div").append(img);
				}
			}
		}
			
	})
}


